#Copyright (C) Nial Peters 2012
#
#This file is part of AvoScan.
#
#AvoScan is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#AvoScan is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with AvoScan.  If not, see <http://www.gnu.org/licenses/>.

"""
The avoscan package provides classes and functions for controlling AvoScanner
spectrometer scanning units. The gui sub-package provides an easy to use wx-based
graphical interface to the avoscan package.
"""

import sys
import os
import os.path


def get_avoscan_rw_dir():
	"""
	Returns the path used by AvoScan for things like caching settings,
	storing templates etc. This is platform dependent, but on Linux it 
	will be in ~/.AvoScan
	"""
	
	if sys.platform == "linux2":
		try:
			you = os.getlogin()
		except OSError:
			you = os.path.expandvars("$LOGNAME")
		
		if(you == "$LOGNAME"):
			raise RuntimeError, "Failed to determine your login name"
		else:
			return os.path.join("/home",you,".AvoScan")
	
	elif sys.platform == "win32":
		#TODO - does this work?
		return os.path.join(os.path.expanduser('~'),".AvoScan")
	
	else:
		raise NotImplementedError("Your OS is not supported by AvoScan yet - please submit patches!")


#make sure that all the directories that we are expecting to exist actually do.
try:
	os.makedirs(os.path.join(get_avoscan_rw_dir(),"templates"))
except OSError:
	#dir already exists
	pass